package de.szut.traineeslife.taks;

import java.util.ArrayList;

import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;

import de.szut.traineeslife.adapter.FilesFromDriveAdapter;
import de.szut.traineeslife.utils.DriveHelper;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.ListView;

public class DownloadFromDriveTask extends AsyncTask<Void,Void,Void> {

	private ProgressDialog dialog;
	private Context mContext;
	private Drive mService;
	private DriveHelper mDriveHelper;
	private String mFileID;
	
	/**
	 * Loads The Files from Drive
	 * @param context
	 * @param service
	 * @param driveHelper
	 * @param fileID
	 */
	public DownloadFromDriveTask(Context context, Drive service,DriveHelper driveHelper,String fileID){
		mContext = context;
		mService = service;
		mDriveHelper = driveHelper;
		mFileID = fileID;
		
	}
	
	@Override
	protected Void doInBackground(Void... params) {
		try {
			mDriveHelper.downlaodFileFromDrive(mService, mFileID);			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	protected void onPostExecute(Void result) {
		super.onPostExecute(result);
		if (dialog != null) {
			dialog.dismiss();
		}
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		dialog = new ProgressDialog(mContext);
		dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		dialog.setMessage("Lädt Dokumente von Drive....");
		dialog.setCancelable(false);
		dialog.show();
	}

	
}
